package org.metasketch.file;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import org.metasketch.editor.Project;

public class FileHandler {

	public String getPath(Project project) throws Throwable {

		// TODO check to see if the editor is dirty, if so, ask to confirm....
		

		JFileChooser chooser = new JFileChooser();
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

		String path = project.getPath();
		if (path == null)
			path = ".";

		chooser.setCurrentDirectory(new File(path));

		int returnVal = chooser.showOpenDialog(null);

		if (returnVal != JFileChooser.APPROVE_OPTION)
			return null;

		File choice = chooser.getSelectedFile();

		if (choice.isDirectory()) {
			return choice.getAbsolutePath();
		}
		
		return null;
	}

}
